package org.ting.j20250110_gobang.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.ting.j20250110_gobang.mapper.UserMapper;
import org.ting.j20250110_gobang.model.User;

@Service
public class UserService {
    @Autowired
    UserMapper userMapper;
    public User login(String username, String password) {
        User user = userMapper.getUserByName(username);
        if(user == null || !user.getPassword().equals(password)) {
            //用户名不存在或者密码错误，返回一个空的用户信息
            return new User();
        }
        return user;
    }

    public Integer register(User user) {
        return userMapper.insertUser(user);
    }

    public Integer userWin(int userId) {
        return userMapper.userWin(userId);
    }

    public Integer userLose(int userId) {
        return userMapper.userLose(userId);
    }
}
